package cn.tmall;

import cart.ICartService;
import cn.tmall.commons.enums.shop.OrderEnum;
import cn.tmall.commons.utils.Maps;
import cn.tmall.commons.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tmall.IOrderService;
import tmall.IShopUserService;

import java.util.Map;

/**
 * @author ：yang
 * @date ：Created in 1/7/2020 2:25 PM
 */
@Service
public class DashboardServiceImpl implements IDashboardService {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private IShopUserService shopUserService;
    @Autowired
    private ICartService cartService;
    @Override
    public Map getDashboardData(){
        long orderCount = orderService.count();
        long userCount = shopUserService.count();
        long cartCount = cartService.count();
        Object orderSumPrice = orderService.get("select sum(real_price) from t_shop_order where status<>"+ OrderEnum.OrderStatusEnum.UN_PAY.getId());
        Map result = Maps.newHashMap(
                "orderCount",orderCount,
                "userCount",userCount,
                "cartCount",cartCount,
                "orderSumPrice", StringUtil.isNotNullOrEmpty(orderSumPrice)?Double.valueOf(orderSumPrice.toString())/100:"0"
        );
        return result;
    }
}
